{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c67af4b7",
   "metadata": {},
   "source": [
    "# 1. 语音录制\n",
    "\n",
    "* 1. 安装和下载模块：pip install 模块名称\n",
    "> 1. SpeechRecognition\n",
    "> 2. Pyaudio\n",
    "> 3. pydub"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "35be7363",
   "metadata": {},
   "outputs": [],
   "source": [
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"16k.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "003718b8",
   "metadata": {},
   "source": [
    "# 2. 语音识别（百度的ASR）auto speech recognition\n",
    "\n",
    "* I/O: 音频文件--> 文本文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ce0a43d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdasr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4ab114c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 1.022361\n",
      "{\"corpus_no\":\"7244774011848605336\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"11035410831686805396\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7244774011848605336\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"11035410831686805396\"}\\n'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdasr.asr('16k.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b5694749",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Request time cost 1.063390\n",
      "{\"corpus_no\":\"7244774016244975127\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"他说他呢？\"],\"sn\":\"945696107581686805397\"}\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'他说他呢？'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bdasr_result = eval(bdasr.asr('16k.wav'))['result'][0]\n",
    "bdasr_result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a46ecc1e",
   "metadata": {},
   "source": [
    "# 3. 自然语言处理（NLP）\n",
    "* I/O: 文本--->文本（文本的生成：文本的理解，文本的处理，文本的生成）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "37b1bfcc",
   "metadata": {},
   "outputs": [],
   "source": [
    "qa = {\n",
    "    \"网络与新媒体专业。\":\"网络与新媒体是一门普通高等学校本科专业，属新闻传播学类专业，学制四年，授予文学学士学位\",\n",
    "    \"你是谁？\":\"我是集美貌和智慧于一体的智能小网同学\",\n",
    "    '你好。':\"你也好，我是智能小新，很高兴为你服务\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "8ecaf2bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import opchat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0ffff611",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: urllib3==1.25.11 in d:\\users\\lenovo\\anaconda3\\lib\\site-packages (1.25.11)\n"
     ]
    }
   ],
   "source": [
    "!pip install -U urllib3==1.25.11\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "90c03bba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# packages in environment at D:\\Users\\lenovo\\anaconda3:\n",
      "#\n",
      "# Name                    Version                   Build  Channel\n",
      "_ipyw_jlab_nb_ext_conf    0.1.0            py39haa95532_0  \n",
      "aiohttp                   3.8.1            py39h2bbff1b_1  \n",
      "aiosignal                 1.2.0              pyhd3eb1b0_0  \n",
      "alabaster                 0.7.12             pyhd3eb1b0_0  \n",
      "anaconda                  2022.05                  py39_0  \n",
      "anaconda-client           1.9.0            py39haa95532_0  \n",
      "anaconda-navigator        2.1.4            py39haa95532_0  \n",
      "anaconda-project          0.10.2             pyhd3eb1b0_0  \n",
      "anyio                     3.5.0            py39haa95532_0  \n",
      "appdirs                   1.4.4              pyhd3eb1b0_0  \n",
      "argon2-cffi               21.3.0             pyhd3eb1b0_0  \n",
      "argon2-cffi-bindings      21.2.0           py39h2bbff1b_0  \n",
      "arrow                     1.2.2              pyhd3eb1b0_0  \n",
      "astroid                   2.6.6            py39haa95532_0  \n",
      "astropy                   5.0.4            py39h080aedc_0  \n",
      "asttokens                 2.0.5              pyhd3eb1b0_0  \n",
      "async-timeout             4.0.1              pyhd3eb1b0_0  \n",
      "atomicwrites              1.4.0                      py_0  \n",
      "attrs                     21.4.0             pyhd3eb1b0_0  \n",
      "automat                   20.2.0                     py_0  \n",
      "autopep8                  1.6.0              pyhd3eb1b0_0  \n",
      "babel                     2.9.1              pyhd3eb1b0_0  \n",
      "backcall                  0.2.0              pyhd3eb1b0_0  \n",
      "backports                 1.1                pyhd3eb1b0_0  \n",
      "backports.functools_lru_cache 1.6.4              pyhd3eb1b0_0  \n",
      "backports.tempfile        1.0                pyhd3eb1b0_1  \n",
      "backports.weakref         1.0.post1                  py_1  \n",
      "bcrypt                    3.2.0            py39h196d8e1_0  \n",
      "beautifulsoup4            4.11.1           py39haa95532_0  \n",
      "binaryornot               0.4.4              pyhd3eb1b0_1  \n",
      "bitarray                  2.4.1            py39h2bbff1b_0  \n",
      "bkcharts                  0.2              py39haa95532_0  \n",
      "black                     19.10b0                    py_0  \n",
      "blas                      1.0                         mkl  \n",
      "bleach                    4.1.0              pyhd3eb1b0_0  \n",
      "blosc                     1.21.0               h19a0ad4_0  \n",
      "bokeh                     2.4.2            py39haa95532_0  \n",
      "boto3                     1.21.32            pyhd3eb1b0_0  \n",
      "botocore                  1.24.32            pyhd3eb1b0_0  \n",
      "bottleneck                1.3.4            py39h080aedc_0  \n",
      "brotli                    1.0.9                ha925a31_2  \n",
      "brotlipy                  0.7.0           py39h2bbff1b_1003  \n",
      "bzip2                     1.0.8                he774522_0  \n",
      "ca-certificates           2022.3.29            haa95532_1  \n",
      "cachetools                4.2.2              pyhd3eb1b0_0  \n",
      "certifi                   2021.10.8        py39haa95532_2  \n",
      "cffi                      1.15.0           py39h2bbff1b_1  \n",
      "cfitsio                   3.470                he774522_6  \n",
      "chardet                   4.0.0           py39haa95532_1003  \n",
      "charls                    2.2.0                h6c2663c_0  \n",
      "charset-normalizer        2.0.4              pyhd3eb1b0_0  \n",
      "click                     8.0.4            py39haa95532_0  \n",
      "cloudpickle               2.0.0              pyhd3eb1b0_0  \n",
      "clyent                    1.2.2            py39haa95532_1  \n",
      "colorama                  0.4.4              pyhd3eb1b0_0  \n",
      "colorcet                  2.0.6              pyhd3eb1b0_0  \n",
      "comtypes                  1.1.10          py39haa95532_1002  \n",
      "conda                     4.12.0           py39haa95532_0  \n",
      "conda-build               3.21.8           py39haa95532_2  \n",
      "conda-content-trust       0.1.1              pyhd3eb1b0_0  \n",
      "conda-env                 2.6.0                haa95532_1  \n",
      "conda-pack                0.6.0              pyhd3eb1b0_0  \n",
      "conda-package-handling    1.8.1            py39h8cc25b3_0  \n",
      "conda-repo-cli            1.0.4              pyhd3eb1b0_0  \n",
      "conda-token               0.3.0              pyhd3eb1b0_0  \n",
      "conda-verify              3.4.2                      py_1  \n",
      "console_shortcut          0.1.1                         4  \n",
      "constantly                15.1.0             pyh2b92418_0  \n",
      "cookiecutter              1.7.3              pyhd3eb1b0_0  \n",
      "cryptography              3.4.8            py39h71e12ea_0  \n",
      "cssselect                 1.1.0              pyhd3eb1b0_0  \n",
      "curl                      7.82.0               h2bbff1b_0  \n",
      "cycler                    0.11.0             pyhd3eb1b0_0  \n",
      "cython                    0.29.28          py39hd77b12b_0  \n",
      "cytoolz                   0.11.0           py39h2bbff1b_0  \n",
      "daal4py                   2021.5.0         py39h8cb3d55_0  \n",
      "dal                       2021.5.0           haa95532_796  \n",
      "dask                      2022.2.1           pyhd3eb1b0_0  \n",
      "dask-core                 2022.2.1           pyhd3eb1b0_0  \n",
      "dataclasses               0.8                pyh6d0b6a4_7  \n",
      "datashader                0.13.0             pyhd3eb1b0_1  \n",
      "datashape                 0.5.4            py39haa95532_1  \n",
      "debugpy                   1.5.1            py39hd77b12b_0  \n",
      "decorator                 5.1.1              pyhd3eb1b0_0  \n",
      "defusedxml                0.7.1              pyhd3eb1b0_0  \n",
      "diff-match-patch          20200713           pyhd3eb1b0_0  \n",
      "distributed               2022.2.1           pyhd3eb1b0_0  \n",
      "docopt                    0.6.2                    pypi_0    pypi\n",
      "docutils                  0.17.1           py39haa95532_1  \n",
      "entrypoints               0.4              py39haa95532_0  \n",
      "et_xmlfile                1.1.0            py39haa95532_0  \n",
      "executing                 0.8.3              pyhd3eb1b0_0  \n",
      "filelock                  3.6.0              pyhd3eb1b0_0  \n",
      "flake8                    3.9.2              pyhd3eb1b0_0  \n",
      "flask                     1.1.2              pyhd3eb1b0_0  \n",
      "fonttools                 4.25.0             pyhd3eb1b0_0  \n",
      "freetype                  2.10.4               hd328e21_0  \n",
      "frozenlist                1.2.0            py39h2bbff1b_0  \n",
      "fsspec                    2022.2.0           pyhd3eb1b0_0  \n",
      "future                    0.18.2           py39haa95532_1  \n",
      "gensim                    4.1.2            py39hd77b12b_0  \n",
      "giflib                    5.2.1                h62dcd97_0  \n",
      "glob2                     0.7                pyhd3eb1b0_0  \n",
      "google-api-core           1.25.1             pyhd3eb1b0_0  \n",
      "google-auth               1.33.0             pyhd3eb1b0_0  \n",
      "google-cloud-core         1.7.1              pyhd3eb1b0_0  \n",
      "google-cloud-storage      1.31.0                     py_0  \n",
      "google-crc32c             1.1.2            py39h2bbff1b_0  \n",
      "google-resumable-media    1.3.1              pyhd3eb1b0_1  \n",
      "googleapis-common-protos  1.53.0           py39h2eaa2aa_0  \n",
      "greenlet                  1.1.1            py39hd77b12b_0  \n",
      "grpcio                    1.42.0           py39hc60d5dd_0  \n",
      "h5py                      3.6.0            py39h3de5c98_0  \n",
      "hdf5                      1.10.6               h7ebc959_0  \n",
      "heapdict                  1.0.1              pyhd3eb1b0_0  \n",
      "holoviews                 1.14.8             pyhd3eb1b0_0  \n",
      "hvplot                    0.7.3              pyhd3eb1b0_1  \n",
      "hyperlink                 21.0.0             pyhd3eb1b0_0  \n",
      "icc_rt                    2019.0.0             h0cc432a_1  \n",
      "icu                       58.2                 ha925a31_3  \n",
      "idna                      3.3                pyhd3eb1b0_0  \n",
      "imagecodecs               2021.8.26        py39ha1f97ea_0  \n",
      "imageio                   2.9.0              pyhd3eb1b0_0  \n",
      "imagesize                 1.3.0              pyhd3eb1b0_0  \n",
      "importlib-metadata        4.11.3           py39haa95532_0  \n",
      "importlib_metadata        4.11.3               hd3eb1b0_0  \n",
      "incremental               21.3.0             pyhd3eb1b0_0  \n",
      "inflection                0.5.1            py39haa95532_0  \n",
      "iniconfig                 1.1.1              pyhd3eb1b0_0  \n",
      "intake                    0.6.5              pyhd3eb1b0_0  \n",
      "intel-openmp              2021.4.0          haa95532_3556  \n",
      "intervaltree              3.1.0              pyhd3eb1b0_0  \n",
      "ipykernel                 6.9.1            py39haa95532_0  \n",
      "ipython                   8.2.0            py39haa95532_0  \n",
      "ipython_genutils          0.2.0              pyhd3eb1b0_1  \n",
      "ipywidgets                7.6.5              pyhd3eb1b0_1  \n",
      "isort                     5.9.3              pyhd3eb1b0_0  \n",
      "itemadapter               0.3.0              pyhd3eb1b0_0  \n",
      "itemloaders               1.0.4              pyhd3eb1b0_1  \n",
      "itsdangerous              2.0.1              pyhd3eb1b0_0  \n",
      "jdcal                     1.4.1              pyhd3eb1b0_0  \n",
      "jedi                      0.18.1           py39haa95532_1  \n",
      "jinja2                    2.11.3             pyhd3eb1b0_0  \n",
      "jinja2-time               0.2.0              pyhd3eb1b0_3  \n",
      "jmespath                  0.10.0             pyhd3eb1b0_0  \n",
      "joblib                    1.1.0              pyhd3eb1b0_0  \n",
      "jpeg                      9e                   h2bbff1b_0  \n",
      "jq                        1.6                  haa95532_1  \n",
      "js2py                     0.74                     pypi_0    pypi\n",
      "json5                     0.9.6              pyhd3eb1b0_0  \n",
      "jsonschema                4.4.0            py39haa95532_0  \n",
      "jupyter                   1.0.0            py39haa95532_7  \n",
      "jupyter-contrib-core      0.4.2                    pypi_0    pypi\n",
      "jupyter-contrib-nbextensions 0.7.0                    pypi_0    pypi\n",
      "jupyter-highlight-selected-word 0.2.0                    pypi_0    pypi\n",
      "jupyter-nbextensions-configurator 0.6.1                    pypi_0    pypi\n",
      "jupyter_client            6.1.12             pyhd3eb1b0_0  \n",
      "jupyter_console           6.4.0              pyhd3eb1b0_0  \n",
      "jupyter_core              4.9.2            py39haa95532_0  \n",
      "jupyter_server            1.13.5             pyhd3eb1b0_0  \n",
      "jupyterlab                3.3.2              pyhd3eb1b0_0  \n",
      "jupyterlab_pygments       0.1.2                      py_0  \n",
      "jupyterlab_server         2.10.3             pyhd3eb1b0_1  \n",
      "jupyterlab_widgets        1.0.0              pyhd3eb1b0_1  \n",
      "keyring                   23.4.0           py39haa95532_0  \n",
      "kiwisolver                1.3.2            py39hd77b12b_0  \n",
      "lazy-object-proxy         1.6.0            py39h2bbff1b_0  \n",
      "lcms2                     2.12                 h83e58a3_0  \n",
      "lerc                      3.0                  hd77b12b_0  \n",
      "libaec                    1.0.4                h33f27b4_1  \n",
      "libarchive                3.4.2                h5e25573_0  \n",
      "libcrc32c                 1.1.1                ha925a31_2  \n",
      "libcurl                   7.82.0               h86230a5_0  \n",
      "libdeflate                1.8                  h2bbff1b_5  \n",
      "libiconv                  1.16                 h2bbff1b_2  \n",
      "liblief                   0.11.5               hd77b12b_1  \n",
      "libpng                    1.6.37               h2a8f88b_0  \n",
      "libprotobuf               3.19.1               h23ce68f_0  \n",
      "libspatialindex           1.9.3                h6c2663c_0  \n",
      "libssh2                   1.10.0               hcd4344a_0  \n",
      "libtiff                   4.2.0                hd0e1b90_0  \n",
      "libwebp                   1.2.2                h2bbff1b_0  \n",
      "libxml2                   2.9.12               h0ad7f3c_0  \n",
      "libxslt                   1.1.34               he774522_0  \n",
      "libzopfli                 1.0.3                ha925a31_0  \n",
      "llvmlite                  0.38.0           py39h23ce68f_0  \n",
      "locket                    0.2.1            py39haa95532_2  \n",
      "lxml                      4.8.0            py39h1985fb9_0  \n",
      "lz4-c                     1.9.3                h2bbff1b_1  \n",
      "lzo                       2.10                 he774522_2  \n",
      "m2w64-libwinpthread-git   5.0.0.4634.697f757               2  \n",
      "markdown                  3.3.4            py39haa95532_0  \n",
      "markupsafe                2.0.1            py39h2bbff1b_0  \n",
      "matplotlib                3.5.1            py39haa95532_1  \n",
      "matplotlib-base           3.5.1            py39hd77b12b_1  \n",
      "matplotlib-inline         0.1.2              pyhd3eb1b0_2  \n",
      "mccabe                    0.6.1            py39haa95532_1  \n",
      "menuinst                  1.4.18           py39h59b6b97_0  \n",
      "mistune                   0.8.4           py39h2bbff1b_1000  \n",
      "mkl                       2021.4.0           haa95532_640  \n",
      "mkl-service               2.4.0            py39h2bbff1b_0  \n",
      "mkl_fft                   1.3.1            py39h277e83a_0  \n",
      "mkl_random                1.2.2            py39hf11a4ad_0  \n",
      "mock                      4.0.3              pyhd3eb1b0_0  \n",
      "mpmath                    1.2.1            py39haa95532_0  \n",
      "msgpack-python            1.0.2            py39h59b6b97_1  \n",
      "msys2-conda-epoch         20160418                      1  \n",
      "multidict                 5.1.0            py39h2bbff1b_2  \n",
      "multipledispatch          0.6.0            py39haa95532_0  \n",
      "munkres                   1.1.4                      py_0  \n",
      "mypy_extensions           0.4.3            py39haa95532_1  \n",
      "navigator-updater         0.2.1                    py39_1  \n",
      "nbclassic                 0.3.5              pyhd3eb1b0_0  \n",
      "nbclient                  0.5.13           py39haa95532_0  \n",
      "nbconvert                 6.4.4            py39haa95532_0  \n",
      "nbformat                  5.3.0            py39haa95532_0  \n",
      "nest-asyncio              1.5.5            py39haa95532_0  \n",
      "networkx                  2.7.1              pyhd3eb1b0_0  \n",
      "nltk                      3.7                pyhd3eb1b0_0  \n",
      "nose                      1.3.7           pyhd3eb1b0_1008  \n",
      "notebook                  6.4.8            py39haa95532_0  \n",
      "numba                     0.55.1           py39hf11a4ad_0  \n",
      "numexpr                   2.8.1            py39hb80d3ca_0  \n",
      "numpy                     1.21.5           py39h7a0a035_1  \n",
      "numpy-base                1.21.5           py39hca35cd5_1  \n",
      "numpydoc                  1.2                pyhd3eb1b0_0  \n",
      "olefile                   0.46               pyhd3eb1b0_0  \n",
      "openai                    0.27.7                   pypi_0    pypi\n",
      "openjpeg                  2.4.0                h4fc8c34_0  \n",
      "openpyxl                  3.0.9              pyhd3eb1b0_0  \n",
      "openssl                   1.1.1n               h2bbff1b_0  \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "packaging                 21.3               pyhd3eb1b0_0  \n",
      "pandas                    1.4.2            py39hd77b12b_0  \n",
      "pandocfilters             1.5.0              pyhd3eb1b0_0  \n",
      "panel                     0.13.0           py39haa95532_0  \n",
      "param                     1.12.0             pyhd3eb1b0_0  \n",
      "paramiko                  2.8.1              pyhd3eb1b0_0  \n",
      "parsel                    1.6.0            py39haa95532_0  \n",
      "parso                     0.8.3              pyhd3eb1b0_0  \n",
      "partd                     1.2.0              pyhd3eb1b0_1  \n",
      "pathspec                  0.7.0                      py_0  \n",
      "patsy                     0.5.2            py39haa95532_1  \n",
      "pep8                      1.7.1            py39haa95532_0  \n",
      "pexpect                   4.8.0              pyhd3eb1b0_3  \n",
      "pickleshare               0.7.5           pyhd3eb1b0_1003  \n",
      "pillow                    9.0.1            py39hdc2b20a_0  \n",
      "pip                       21.2.4           py39haa95532_0  \n",
      "pipwin                    0.5.2                    pypi_0    pypi\n",
      "pkginfo                   1.8.2              pyhd3eb1b0_0  \n",
      "plotly                    5.6.0              pyhd3eb1b0_0  \n",
      "pluggy                    1.0.0            py39haa95532_1  \n",
      "powershell_shortcut       0.0.1                         3  \n",
      "poyo                      0.5.0              pyhd3eb1b0_0  \n",
      "prettytable               3.7.0                    pypi_0    pypi\n",
      "prometheus_client         0.13.1             pyhd3eb1b0_0  \n",
      "prompt-toolkit            3.0.20             pyhd3eb1b0_0  \n",
      "prompt_toolkit            3.0.20               hd3eb1b0_0  \n",
      "protego                   0.1.16                     py_0  \n",
      "protobuf                  3.19.1           py39hd77b12b_0  \n",
      "psutil                    5.8.0            py39h2bbff1b_1  \n",
      "ptyprocess                0.7.0              pyhd3eb1b0_2  \n",
      "pure_eval                 0.2.2              pyhd3eb1b0_0  \n",
      "py                        1.11.0             pyhd3eb1b0_0  \n",
      "py-lief                   0.11.5           py39hd77b12b_1  \n",
      "pyasn1                    0.4.8              pyhd3eb1b0_0  \n",
      "pyasn1-modules            0.2.8                      py_0  \n",
      "pyaudio                   0.2.13                   pypi_0    pypi\n",
      "pycodestyle               2.7.0              pyhd3eb1b0_0  \n",
      "pycosat                   0.6.3            py39h2bbff1b_0  \n",
      "pycparser                 2.21               pyhd3eb1b0_0  \n",
      "pyct                      0.4.6            py39haa95532_0  \n",
      "pycurl                    7.44.1           py39hcd4344a_1  \n",
      "pydispatcher              2.0.5            py39haa95532_2  \n",
      "pydocstyle                6.1.1              pyhd3eb1b0_0  \n",
      "pydub                     0.25.1                   pypi_0    pypi\n",
      "pyecharts                 2.0.3                    pypi_0    pypi\n",
      "pyerfa                    2.0.0            py39h2bbff1b_0  \n",
      "pyflakes                  2.3.1              pyhd3eb1b0_0  \n",
      "pygments                  2.11.2             pyhd3eb1b0_0  \n",
      "pyhamcrest                2.0.2              pyhd3eb1b0_2  \n",
      "pyjsparser                2.7.1                    pypi_0    pypi\n",
      "pyjwt                     2.1.0            py39haa95532_0  \n",
      "pylint                    2.9.6            py39haa95532_1  \n",
      "pyls-spyder               0.4.0              pyhd3eb1b0_0  \n",
      "pynacl                    1.4.0            py39hbd8134f_1  \n",
      "pyodbc                    4.0.32           py39hd77b12b_1  \n",
      "pyopenssl                 21.0.0             pyhd3eb1b0_1  \n",
      "pyparsing                 3.0.4              pyhd3eb1b0_0  \n",
      "pyprind                   2.11.3                   pypi_0    pypi\n",
      "pyqt                      5.9.2            py39hd77b12b_6  \n",
      "pyreadline                2.1              py39haa95532_1  \n",
      "pyrsistent                0.18.0           py39h196d8e1_0  \n",
      "pysmartdl                 1.3.4                    pypi_0    pypi\n",
      "pysocks                   1.7.1            py39haa95532_0  \n",
      "pytables                  3.6.1            py39h56d22b6_1  \n",
      "pytest                    7.1.1            py39haa95532_0  \n",
      "python                    3.9.12               h6244533_0  \n",
      "python-dateutil           2.8.2              pyhd3eb1b0_0  \n",
      "python-fastjsonschema     2.15.1             pyhd3eb1b0_0  \n",
      "python-libarchive-c       2.9                pyhd3eb1b0_1  \n",
      "python-lsp-black          1.0.0              pyhd3eb1b0_0  \n",
      "python-lsp-jsonrpc        1.0.0              pyhd3eb1b0_0  \n",
      "python-lsp-server         1.2.4              pyhd3eb1b0_0  \n",
      "python-slugify            5.0.2              pyhd3eb1b0_0  \n",
      "python-snappy             0.6.0            py39hd77b12b_3  \n",
      "pytz                      2021.3             pyhd3eb1b0_0  \n",
      "pyviz_comms               2.0.2              pyhd3eb1b0_0  \n",
      "pywavelets                1.3.0            py39h2bbff1b_0  \n",
      "pywin32                   302              py39h2bbff1b_2  \n",
      "pywin32-ctypes            0.2.0           py39haa95532_1000  \n",
      "pywinpty                  2.0.2            py39h5da7b33_0  \n",
      "pyyaml                    6.0              py39h2bbff1b_1  \n",
      "pyzmq                     22.3.0           py39hd77b12b_2  \n",
      "qdarkstyle                3.0.2              pyhd3eb1b0_0  \n",
      "qstylizer                 0.1.10             pyhd3eb1b0_0  \n",
      "qt                        5.9.7            vc14h73c81de_0  \n",
      "qtawesome                 1.0.3              pyhd3eb1b0_0  \n",
      "qtconsole                 5.3.0              pyhd3eb1b0_0  \n",
      "qtpy                      2.0.1              pyhd3eb1b0_0  \n",
      "queuelib                  1.5.0            py39haa95532_0  \n",
      "regex                     2022.3.15        py39h2bbff1b_0  \n",
      "requests                  2.27.1             pyhd3eb1b0_0  \n",
      "requests-file             1.5.1              pyhd3eb1b0_0  \n",
      "rope                      0.22.0             pyhd3eb1b0_0  \n",
      "rsa                       4.7.2              pyhd3eb1b0_1  \n",
      "rtree                     0.9.7            py39h2eaa2aa_1  \n",
      "ruamel_yaml               0.15.100         py39h2bbff1b_0  \n",
      "s3transfer                0.5.0              pyhd3eb1b0_0  \n",
      "scikit-image              0.19.2           py39hf11a4ad_0  \n",
      "scikit-learn              1.0.2            py39hf11a4ad_1  \n",
      "scikit-learn-intelex      2021.5.0         py39haa95532_0  \n",
      "scipy                     1.7.3            py39h0a974cb_0  \n",
      "scrapy                    2.6.1            py39haa95532_0  \n",
      "seaborn                   0.11.2             pyhd3eb1b0_0  \n",
      "send2trash                1.8.0              pyhd3eb1b0_1  \n",
      "service_identity          18.1.0             pyhd3eb1b0_1  \n",
      "setuptools                61.2.0           py39haa95532_0  \n",
      "simplejson                3.19.1                   pypi_0    pypi\n",
      "sip                       4.19.13          py39hd77b12b_0  \n",
      "six                       1.16.0             pyhd3eb1b0_1  \n",
      "smart_open                5.1.0              pyhd3eb1b0_0  \n",
      "snappy                    1.1.9                h6c2663c_0  \n",
      "sniffio                   1.2.0            py39haa95532_1  \n",
      "snowballstemmer           2.2.0              pyhd3eb1b0_0  \n",
      "sortedcollections         2.1.0              pyhd3eb1b0_0  \n",
      "sortedcontainers          2.4.0              pyhd3eb1b0_0  \n",
      "soupsieve                 2.3.1              pyhd3eb1b0_0  \n",
      "speechrecognition         3.10.0                   pypi_0    pypi\n",
      "sphinx                    4.4.0              pyhd3eb1b0_0  \n",
      "sphinxcontrib-applehelp   1.0.2              pyhd3eb1b0_0  \n",
      "sphinxcontrib-devhelp     1.0.2              pyhd3eb1b0_0  \n",
      "sphinxcontrib-htmlhelp    2.0.0              pyhd3eb1b0_0  \n",
      "sphinxcontrib-jsmath      1.0.1              pyhd3eb1b0_0  \n",
      "sphinxcontrib-qthelp      1.0.3              pyhd3eb1b0_0  \n",
      "sphinxcontrib-serializinghtml 1.1.5              pyhd3eb1b0_0  \n",
      "spyder                    5.1.5            py39haa95532_1  \n",
      "spyder-kernels            2.1.3            py39haa95532_0  \n",
      "sqlalchemy                1.4.32           py39h2bbff1b_0  \n",
      "sqlite                    3.38.2               h2bbff1b_0  \n",
      "stack_data                0.2.0              pyhd3eb1b0_0  \n",
      "statsmodels               0.13.2           py39h2bbff1b_0  \n",
      "sympy                     1.10.1           py39haa95532_0  \n",
      "tabulate                  0.8.9            py39haa95532_0  \n",
      "tbb                       2021.5.0             h59b6b97_0  \n",
      "tbb4py                    2021.5.0         py39h59b6b97_0  \n",
      "tblib                     1.7.0              pyhd3eb1b0_0  \n",
      "tenacity                  8.0.1            py39haa95532_0  \n",
      "terminado                 0.13.1           py39haa95532_0  \n",
      "testpath                  0.5.0              pyhd3eb1b0_0  \n",
      "text-unidecode            1.3                pyhd3eb1b0_0  \n",
      "textdistance              4.2.1              pyhd3eb1b0_0  \n",
      "threadpoolctl             2.2.0              pyh0d69192_0  \n",
      "three-merge               0.1.1              pyhd3eb1b0_0  \n",
      "tifffile                  2021.7.2           pyhd3eb1b0_2  \n",
      "tinycss                   0.4             pyhd3eb1b0_1002  \n",
      "tk                        8.6.11               h2bbff1b_0  \n",
      "tldextract                3.2.0              pyhd3eb1b0_0  \n",
      "toml                      0.10.2             pyhd3eb1b0_0  \n",
      "tomli                     1.2.2              pyhd3eb1b0_0  \n",
      "toolz                     0.11.2             pyhd3eb1b0_0  \n",
      "tornado                   6.1              py39h2bbff1b_0  \n",
      "tqdm                      4.64.0           py39haa95532_0  \n",
      "traitlets                 5.1.1              pyhd3eb1b0_0  \n",
      "twisted                   22.2.0           py39h2bbff1b_0  \n",
      "twisted-iocpsupport       1.0.2            py39h2bbff1b_0  \n",
      "typed-ast                 1.4.3            py39h2bbff1b_1  \n",
      "typing-extensions         4.1.1                hd3eb1b0_0  \n",
      "typing_extensions         4.1.1              pyh06a4308_0  \n",
      "tzdata                    2023.3                   pypi_0    pypi\n",
      "tzlocal                   5.0.1                    pypi_0    pypi\n",
      "ujson                     5.1.0            py39hd77b12b_0  \n",
      "unidecode                 1.2.0              pyhd3eb1b0_0  \n",
      "urllib3                   1.25.11                  pypi_0    pypi\n",
      "vc                        14.2                 h21ff451_1  \n",
      "vs2015_runtime            14.27.29016          h5e58377_2  \n",
      "w3lib                     1.21.0             pyhd3eb1b0_0  \n",
      "watchdog                  2.1.6            py39haa95532_0  \n",
      "wcwidth                   0.2.5              pyhd3eb1b0_0  \n",
      "webencodings              0.5.1            py39haa95532_1  \n",
      "websocket-client          0.58.0           py39haa95532_4  \n",
      "werkzeug                  2.0.3              pyhd3eb1b0_0  \n",
      "wheel                     0.37.1             pyhd3eb1b0_0  \n",
      "widgetsnbextension        3.5.2            py39haa95532_0  \n",
      "win_inet_pton             1.1.0            py39haa95532_0  \n",
      "win_unicode_console       0.5              py39haa95532_0  \n",
      "wincertstore              0.2              py39haa95532_2  \n",
      "winpty                    0.4.3                         4  \n",
      "wrapt                     1.12.1           py39h196d8e1_1  \n",
      "xarray                    0.20.1             pyhd3eb1b0_1  \n",
      "xlrd                      2.0.1              pyhd3eb1b0_0  \n",
      "xlsxwriter                3.0.3              pyhd3eb1b0_0  \n",
      "xlwings                   0.24.9           py39haa95532_0  \n",
      "xz                        5.2.5                h62dcd97_0  \n",
      "yaml                      0.2.5                he774522_0  \n",
      "yapf                      0.31.0             pyhd3eb1b0_0  \n",
      "yarl                      1.6.3            py39h2bbff1b_0  \n",
      "zfp                       0.5.5                hd77b12b_6  \n",
      "zict                      2.0.0              pyhd3eb1b0_0  \n",
      "zipp                      3.7.0              pyhd3eb1b0_0  \n",
      "zlib                      1.2.12               h8cc25b3_2  \n",
      "zope                      1.0              py39haa95532_1  \n",
      "zope.interface            5.4.0            py39h2bbff1b_0  \n",
      "zstd                      1.4.9                h19a0ad4_0  \n"
     ]
    }
   ],
   "source": [
    "!conda list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "baca1d24",
   "metadata": {},
   "outputs": [
    {
     "ename": "APIConnectionError",
     "evalue": "Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002C10C27AA60>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。'))",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTimeoutError\u001b[0m                              Traceback (most recent call last)",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connection.py:159\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    158\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 159\u001b[0m     conn \u001b[38;5;241m=\u001b[39m connection\u001b[38;5;241m.\u001b[39mcreate_connection(\n\u001b[0;32m    160\u001b[0m         (\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_dns_host, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mport), \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtimeout, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mextra_kw\n\u001b[0;32m    161\u001b[0m     )\n\u001b[0;32m    163\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m SocketTimeout:\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\util\\connection.py:84\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m     83\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m err \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m---> 84\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m err\n\u001b[0;32m     86\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m socket\u001b[38;5;241m.\u001b[39merror(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgetaddrinfo returns an empty list\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\util\\connection.py:74\u001b[0m, in \u001b[0;36mcreate_connection\u001b[1;34m(address, timeout, source_address, socket_options)\u001b[0m\n\u001b[0;32m     73\u001b[0m     sock\u001b[38;5;241m.\u001b[39mbind(source_address)\n\u001b[1;32m---> 74\u001b[0m \u001b[43msock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43msa\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     75\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m sock\n",
      "\u001b[1;31mTimeoutError\u001b[0m: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mNewConnectionError\u001b[0m                        Traceback (most recent call last)",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:670\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    669\u001b[0m \u001b[38;5;66;03m# Make the request on the httplib connection object.\u001b[39;00m\n\u001b[1;32m--> 670\u001b[0m httplib_response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    671\u001b[0m \u001b[43m    \u001b[49m\u001b[43mconn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    672\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    673\u001b[0m \u001b[43m    \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    674\u001b[0m \u001b[43m    \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout_obj\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    675\u001b[0m \u001b[43m    \u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    676\u001b[0m \u001b[43m    \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    677\u001b[0m \u001b[43m    \u001b[49m\u001b[43mchunked\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mchunked\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    678\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    680\u001b[0m \u001b[38;5;66;03m# If we're going to release the connection in ``finally:``, then\u001b[39;00m\n\u001b[0;32m    681\u001b[0m \u001b[38;5;66;03m# the response doesn't need to know about the connection. Otherwise\u001b[39;00m\n\u001b[0;32m    682\u001b[0m \u001b[38;5;66;03m# it will also try to release it and we'll have a double-release\u001b[39;00m\n\u001b[0;32m    683\u001b[0m \u001b[38;5;66;03m# mess.\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:381\u001b[0m, in \u001b[0;36mHTTPConnectionPool._make_request\u001b[1;34m(self, conn, method, url, timeout, chunked, **httplib_request_kw)\u001b[0m\n\u001b[0;32m    380\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 381\u001b[0m     \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_validate_conn\u001b[49m\u001b[43m(\u001b[49m\u001b[43mconn\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    382\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m (SocketTimeout, BaseSSLError) \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m    383\u001b[0m     \u001b[38;5;66;03m# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:978\u001b[0m, in \u001b[0;36mHTTPSConnectionPool._validate_conn\u001b[1;34m(self, conn)\u001b[0m\n\u001b[0;32m    977\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mgetattr\u001b[39m(conn, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msock\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m):  \u001b[38;5;66;03m# AppEngine might not have  `.sock`\u001b[39;00m\n\u001b[1;32m--> 978\u001b[0m     \u001b[43mconn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconnect\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    980\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m conn\u001b[38;5;241m.\u001b[39mis_verified:\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connection.py:309\u001b[0m, in \u001b[0;36mHTTPSConnection.connect\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    307\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mconnect\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m    308\u001b[0m     \u001b[38;5;66;03m# Add certificate verification\u001b[39;00m\n\u001b[1;32m--> 309\u001b[0m     conn \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_new_conn\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    310\u001b[0m     hostname \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhost\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connection.py:171\u001b[0m, in \u001b[0;36mHTTPConnection._new_conn\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    170\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m SocketError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m--> 171\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m NewConnectionError(\n\u001b[0;32m    172\u001b[0m         \u001b[38;5;28mself\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mFailed to establish a new connection: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m e\n\u001b[0;32m    173\u001b[0m     )\n\u001b[0;32m    175\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m conn\n",
      "\u001b[1;31mNewConnectionError\u001b[0m: <urllib3.connection.HTTPSConnection object at 0x000002C10C27AA60>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mMaxRetryError\u001b[0m                             Traceback (most recent call last)",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\requests\\adapters.py:440\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    439\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m chunked:\n\u001b[1;32m--> 440\u001b[0m     resp \u001b[38;5;241m=\u001b[39m \u001b[43mconn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43murlopen\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    441\u001b[0m \u001b[43m        \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    442\u001b[0m \u001b[43m        \u001b[49m\u001b[43murl\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    443\u001b[0m \u001b[43m        \u001b[49m\u001b[43mbody\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbody\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    444\u001b[0m \u001b[43m        \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    445\u001b[0m \u001b[43m        \u001b[49m\u001b[43mredirect\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    446\u001b[0m \u001b[43m        \u001b[49m\u001b[43massert_same_host\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    447\u001b[0m \u001b[43m        \u001b[49m\u001b[43mpreload_content\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    448\u001b[0m \u001b[43m        \u001b[49m\u001b[43mdecode_content\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m    449\u001b[0m \u001b[43m        \u001b[49m\u001b[43mretries\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmax_retries\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    450\u001b[0m \u001b[43m        \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\n\u001b[0;32m    451\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    453\u001b[0m \u001b[38;5;66;03m# Send the request.\u001b[39;00m\n\u001b[0;32m    454\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:754\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    751\u001b[0m     log\u001b[38;5;241m.\u001b[39mwarning(\n\u001b[0;32m    752\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRetrying (\u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m) after connection broken by \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, retries, err, url\n\u001b[0;32m    753\u001b[0m     )\n\u001b[1;32m--> 754\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39murlopen(\n\u001b[0;32m    755\u001b[0m         method,\n\u001b[0;32m    756\u001b[0m         url,\n\u001b[0;32m    757\u001b[0m         body,\n\u001b[0;32m    758\u001b[0m         headers,\n\u001b[0;32m    759\u001b[0m         retries,\n\u001b[0;32m    760\u001b[0m         redirect,\n\u001b[0;32m    761\u001b[0m         assert_same_host,\n\u001b[0;32m    762\u001b[0m         timeout\u001b[38;5;241m=\u001b[39mtimeout,\n\u001b[0;32m    763\u001b[0m         pool_timeout\u001b[38;5;241m=\u001b[39mpool_timeout,\n\u001b[0;32m    764\u001b[0m         release_conn\u001b[38;5;241m=\u001b[39mrelease_conn,\n\u001b[0;32m    765\u001b[0m         chunked\u001b[38;5;241m=\u001b[39mchunked,\n\u001b[0;32m    766\u001b[0m         body_pos\u001b[38;5;241m=\u001b[39mbody_pos,\n\u001b[0;32m    767\u001b[0m         \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mresponse_kw\n\u001b[0;32m    768\u001b[0m     )\n\u001b[0;32m    770\u001b[0m \u001b[38;5;66;03m# Handle redirect?\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:754\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    751\u001b[0m     log\u001b[38;5;241m.\u001b[39mwarning(\n\u001b[0;32m    752\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRetrying (\u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m) after connection broken by \u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m: \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, retries, err, url\n\u001b[0;32m    753\u001b[0m     )\n\u001b[1;32m--> 754\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39murlopen(\n\u001b[0;32m    755\u001b[0m         method,\n\u001b[0;32m    756\u001b[0m         url,\n\u001b[0;32m    757\u001b[0m         body,\n\u001b[0;32m    758\u001b[0m         headers,\n\u001b[0;32m    759\u001b[0m         retries,\n\u001b[0;32m    760\u001b[0m         redirect,\n\u001b[0;32m    761\u001b[0m         assert_same_host,\n\u001b[0;32m    762\u001b[0m         timeout\u001b[38;5;241m=\u001b[39mtimeout,\n\u001b[0;32m    763\u001b[0m         pool_timeout\u001b[38;5;241m=\u001b[39mpool_timeout,\n\u001b[0;32m    764\u001b[0m         release_conn\u001b[38;5;241m=\u001b[39mrelease_conn,\n\u001b[0;32m    765\u001b[0m         chunked\u001b[38;5;241m=\u001b[39mchunked,\n\u001b[0;32m    766\u001b[0m         body_pos\u001b[38;5;241m=\u001b[39mbody_pos,\n\u001b[0;32m    767\u001b[0m         \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mresponse_kw\n\u001b[0;32m    768\u001b[0m     )\n\u001b[0;32m    770\u001b[0m \u001b[38;5;66;03m# Handle redirect?\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\connectionpool.py:726\u001b[0m, in \u001b[0;36mHTTPConnectionPool.urlopen\u001b[1;34m(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)\u001b[0m\n\u001b[0;32m    724\u001b[0m     e \u001b[38;5;241m=\u001b[39m ProtocolError(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mConnection aborted.\u001b[39m\u001b[38;5;124m\"\u001b[39m, e)\n\u001b[1;32m--> 726\u001b[0m retries \u001b[38;5;241m=\u001b[39m \u001b[43mretries\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mincrement\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    727\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merror\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43me\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_pool\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_stacktrace\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msys\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexc_info\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[0;32m    728\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    729\u001b[0m retries\u001b[38;5;241m.\u001b[39msleep()\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\urllib3\\util\\retry.py:446\u001b[0m, in \u001b[0;36mRetry.increment\u001b[1;34m(self, method, url, response, error, _pool, _stacktrace)\u001b[0m\n\u001b[0;32m    445\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m new_retry\u001b[38;5;241m.\u001b[39mis_exhausted():\n\u001b[1;32m--> 446\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m MaxRetryError(_pool, url, error \u001b[38;5;129;01mor\u001b[39;00m ResponseError(cause))\n\u001b[0;32m    448\u001b[0m log\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIncremented Retry for (url=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m): \u001b[39m\u001b[38;5;132;01m%r\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, url, new_retry)\n",
      "\u001b[1;31mMaxRetryError\u001b[0m: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002C10C27AA60>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。'))",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mConnectionError\u001b[0m                           Traceback (most recent call last)",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py:520\u001b[0m, in \u001b[0;36mAPIRequestor.request_raw\u001b[1;34m(self, method, url, params, supplied_headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[0;32m    519\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 520\u001b[0m     result \u001b[38;5;241m=\u001b[39m \u001b[43m_thread_context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    521\u001b[0m \u001b[43m        \u001b[49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    522\u001b[0m \u001b[43m        \u001b[49m\u001b[43mabs_url\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    523\u001b[0m \u001b[43m        \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    524\u001b[0m \u001b[43m        \u001b[49m\u001b[43mdata\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    525\u001b[0m \u001b[43m        \u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    526\u001b[0m \u001b[43m        \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    527\u001b[0m \u001b[43m        \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest_timeout\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mrequest_timeout\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01melse\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mTIMEOUT_SECS\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    528\u001b[0m \u001b[43m        \u001b[49m\u001b[43mproxies\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_thread_context\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msession\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mproxies\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    529\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    530\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m requests\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mTimeout \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\requests\\sessions.py:529\u001b[0m, in \u001b[0;36mSession.request\u001b[1;34m(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)\u001b[0m\n\u001b[0;32m    528\u001b[0m send_kwargs\u001b[38;5;241m.\u001b[39mupdate(settings)\n\u001b[1;32m--> 529\u001b[0m resp \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39msend(prep, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39msend_kwargs)\n\u001b[0;32m    531\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m resp\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\requests\\sessions.py:645\u001b[0m, in \u001b[0;36mSession.send\u001b[1;34m(self, request, **kwargs)\u001b[0m\n\u001b[0;32m    644\u001b[0m \u001b[38;5;66;03m# Send the request\u001b[39;00m\n\u001b[1;32m--> 645\u001b[0m r \u001b[38;5;241m=\u001b[39m adapter\u001b[38;5;241m.\u001b[39msend(request, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m    647\u001b[0m \u001b[38;5;66;03m# Total elapsed time of the request (approximately)\u001b[39;00m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\requests\\adapters.py:519\u001b[0m, in \u001b[0;36mHTTPAdapter.send\u001b[1;34m(self, request, stream, timeout, verify, cert, proxies)\u001b[0m\n\u001b[0;32m    517\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m SSLError(e, request\u001b[38;5;241m=\u001b[39mrequest)\n\u001b[1;32m--> 519\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mConnectionError\u001b[39;00m(e, request\u001b[38;5;241m=\u001b[39mrequest)\n\u001b[0;32m    521\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m ClosedPoolError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
      "\u001b[1;31mConnectionError\u001b[0m: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002C10C27AA60>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。'))",
      "\nThe above exception was the direct cause of the following exception:\n",
      "\u001b[1;31mAPIConnectionError\u001b[0m                        Traceback (most recent call last)",
      "Input \u001b[1;32mIn [18]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mopchat\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mopenai_chat\u001b[49m\u001b[43m(\u001b[49m\u001b[43mbdasr_result\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m result\n",
      "File \u001b[1;32mF:\\API人工智能\\api-artificial-intelligence\\语音\\opchat.py:11\u001b[0m, in \u001b[0;36mopenai_chat\u001b[1;34m(question)\u001b[0m\n\u001b[0;32m      5\u001b[0m openai\u001b[38;5;241m.\u001b[39mapi_key \u001b[38;5;241m=\u001b[39m api_key\n\u001b[0;32m      7\u001b[0m \u001b[38;5;66;03m#获取用户输入的问题\u001b[39;00m\n\u001b[0;32m      8\u001b[0m \u001b[38;5;66;03m#question = input(\"请输入问题：\")\u001b[39;00m\n\u001b[0;32m      9\u001b[0m \n\u001b[0;32m     10\u001b[0m \u001b[38;5;66;03m#调用openai的api\u001b[39;00m\n\u001b[1;32m---> 11\u001b[0m completion \u001b[38;5;241m=\u001b[39m \u001b[43mopenai\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mChatCompletion\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m     12\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmodel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mgpt-3.5-turbo\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m     13\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmessages\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[43m{\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrole\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43muser\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m     14\u001b[0m \u001b[43m                 \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcontent\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mquestion\u001b[49m\u001b[43m}\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m     15\u001b[0m \u001b[43m    \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m4000\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m     16\u001b[0m \u001b[43m    \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0.8\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m     17\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     18\u001b[0m \u001b[38;5;66;03m#打印答案\u001b[39;00m\n\u001b[0;32m     19\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m completion[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mchoices\u001b[39m\u001b[38;5;124m\"\u001b[39m][\u001b[38;5;241m0\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmessage\u001b[39m\u001b[38;5;124m\"\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\openai\\api_resources\\chat_completion.py:25\u001b[0m, in \u001b[0;36mChatCompletion.create\u001b[1;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[0;32m     23\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m     24\u001b[0m     \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m---> 25\u001b[0m         \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28msuper\u001b[39m()\u001b[38;5;241m.\u001b[39mcreate(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m     26\u001b[0m     \u001b[38;5;28;01mexcept\u001b[39;00m TryAgain \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m     27\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m timeout \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m>\u001b[39m start \u001b[38;5;241m+\u001b[39m timeout:\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\openai\\api_resources\\abstract\\engine_api_resource.py:153\u001b[0m, in \u001b[0;36mEngineAPIResource.create\u001b[1;34m(cls, api_key, api_base, api_type, request_id, api_version, organization, **params)\u001b[0m\n\u001b[0;32m    127\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[0;32m    128\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate\u001b[39m(\n\u001b[0;32m    129\u001b[0m     \u001b[38;5;28mcls\u001b[39m,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    136\u001b[0m     \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mparams,\n\u001b[0;32m    137\u001b[0m ):\n\u001b[0;32m    138\u001b[0m     (\n\u001b[0;32m    139\u001b[0m         deployment_id,\n\u001b[0;32m    140\u001b[0m         engine,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    150\u001b[0m         api_key, api_base, api_type, api_version, organization, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mparams\n\u001b[0;32m    151\u001b[0m     )\n\u001b[1;32m--> 153\u001b[0m     response, _, api_key \u001b[38;5;241m=\u001b[39m \u001b[43mrequestor\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    154\u001b[0m \u001b[43m        \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mpost\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m    155\u001b[0m \u001b[43m        \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    156\u001b[0m \u001b[43m        \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    157\u001b[0m \u001b[43m        \u001b[49m\u001b[43mheaders\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    158\u001b[0m \u001b[43m        \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    159\u001b[0m \u001b[43m        \u001b[49m\u001b[43mrequest_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    160\u001b[0m \u001b[43m        \u001b[49m\u001b[43mrequest_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    161\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    163\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m stream:\n\u001b[0;32m    164\u001b[0m         \u001b[38;5;66;03m# must be an iterator\u001b[39;00m\n\u001b[0;32m    165\u001b[0m         \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(response, OpenAIResponse)\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py:220\u001b[0m, in \u001b[0;36mAPIRequestor.request\u001b[1;34m(self, method, url, params, headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[0;32m    209\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrequest\u001b[39m(\n\u001b[0;32m    210\u001b[0m     \u001b[38;5;28mself\u001b[39m,\n\u001b[0;32m    211\u001b[0m     method,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    218\u001b[0m     request_timeout: Optional[Union[\u001b[38;5;28mfloat\u001b[39m, Tuple[\u001b[38;5;28mfloat\u001b[39m, \u001b[38;5;28mfloat\u001b[39m]]] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m    219\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Tuple[Union[OpenAIResponse, Iterator[OpenAIResponse]], \u001b[38;5;28mbool\u001b[39m, \u001b[38;5;28mstr\u001b[39m]:\n\u001b[1;32m--> 220\u001b[0m     result \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest_raw\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m    221\u001b[0m \u001b[43m        \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlower\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    222\u001b[0m \u001b[43m        \u001b[49m\u001b[43murl\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    223\u001b[0m \u001b[43m        \u001b[49m\u001b[43mparams\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    224\u001b[0m \u001b[43m        \u001b[49m\u001b[43msupplied_headers\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheaders\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    225\u001b[0m \u001b[43m        \u001b[49m\u001b[43mfiles\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfiles\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    226\u001b[0m \u001b[43m        \u001b[49m\u001b[43mstream\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    227\u001b[0m \u001b[43m        \u001b[49m\u001b[43mrequest_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    228\u001b[0m \u001b[43m        \u001b[49m\u001b[43mrequest_timeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrequest_timeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m    229\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    230\u001b[0m     resp, got_stream \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_interpret_response(result, stream)\n\u001b[0;32m    231\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m resp, got_stream, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mapi_key\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\openai\\api_requestor.py:533\u001b[0m, in \u001b[0;36mAPIRequestor.request_raw\u001b[1;34m(self, method, url, params, supplied_headers, files, stream, request_id, request_timeout)\u001b[0m\n\u001b[0;32m    531\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m error\u001b[38;5;241m.\u001b[39mTimeout(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRequest timed out: \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(e)) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m    532\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m requests\u001b[38;5;241m.\u001b[39mexceptions\u001b[38;5;241m.\u001b[39mRequestException \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[1;32m--> 533\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m error\u001b[38;5;241m.\u001b[39mAPIConnectionError(\n\u001b[0;32m    534\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError communicating with OpenAI: \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(e)\n\u001b[0;32m    535\u001b[0m     ) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m    536\u001b[0m util\u001b[38;5;241m.\u001b[39mlog_debug(\n\u001b[0;32m    537\u001b[0m     \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOpenAI API response\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m    538\u001b[0m     path\u001b[38;5;241m=\u001b[39mabs_url,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    541\u001b[0m     request_id\u001b[38;5;241m=\u001b[39mresult\u001b[38;5;241m.\u001b[39mheaders\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mX-Request-Id\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m    542\u001b[0m )\n\u001b[0;32m    543\u001b[0m \u001b[38;5;66;03m# Don't read the whole stream for debug logging unless necessary.\u001b[39;00m\n",
      "\u001b[1;31mAPIConnectionError\u001b[0m: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/chat/completions (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002C10C27AA60>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应，连接尝试失败。'))"
     ]
    }
   ],
   "source": [
    "result = opchat.openai_chat(bdasr_result)\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e549c310",
   "metadata": {},
   "source": [
    "# 4. 语音合成（百度的TTS）text to speech\n",
    "* I/O：文本文件--> 音频文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "72ca52f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdtts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a8301749",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'result' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [20]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m bdtts\u001b[38;5;241m.\u001b[39mtts(\u001b[43mresult\u001b[49m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'result' is not defined"
     ]
    }
   ],
   "source": [
    "bdtts.tts(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "939251e2",
   "metadata": {},
   "source": [
    "# 5. 播放语音合成的音频"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "b57859a3",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\pydub\\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work\n",
      "  warn(\"Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work\", RuntimeWarning)\n"
     ]
    },
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'result.wav'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [21]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydub\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m AudioSegment\n\u001b[0;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydub\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mplayback\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m play\n\u001b[1;32m----> 3\u001b[0m song \u001b[38;5;241m=\u001b[39m \u001b[43mAudioSegment\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_wav\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mresult.wav\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      4\u001b[0m play(song)\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\pydub\\audio_segment.py:808\u001b[0m, in \u001b[0;36mAudioSegment.from_wav\u001b[1;34m(cls, file, parameters)\u001b[0m\n\u001b[0;32m    806\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[0;32m    807\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mfrom_wav\u001b[39m(\u001b[38;5;28mcls\u001b[39m, file, parameters\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m--> 808\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mcls\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfrom_file\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mwav\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparameters\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mparameters\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\pydub\\audio_segment.py:651\u001b[0m, in \u001b[0;36mAudioSegment.from_file\u001b[1;34m(cls, file, format, codec, parameters, start_second, duration, **kwargs)\u001b[0m\n\u001b[0;32m    649\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[0;32m    650\u001b[0m     filename \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m--> 651\u001b[0m file, close_file \u001b[38;5;241m=\u001b[39m \u001b[43m_fd_or_path_or_tempfile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtempfile\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[0;32m    653\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m:\n\u001b[0;32m    654\u001b[0m     \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m.\u001b[39mlower()\n",
      "File \u001b[1;32mD:\\Users\\lenovo\\anaconda3\\lib\\site-packages\\pydub\\utils.py:60\u001b[0m, in \u001b[0;36m_fd_or_path_or_tempfile\u001b[1;34m(fd, mode, tempfile)\u001b[0m\n\u001b[0;32m     57\u001b[0m     close_fd \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m     59\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(fd, basestring):\n\u001b[1;32m---> 60\u001b[0m     fd \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mfd\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     61\u001b[0m     close_fd \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[0;32m     63\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'result.wav'"
     ]
    }
   ],
   "source": [
    "from pydub import AudioSegment\n",
    "from pydub.playback import play\n",
    "song = AudioSegment.from_wav('result.wav')\n",
    "play(song)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8be6c5ce",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34f659bd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
